<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>Nginx系列二之反向代理 | Hexo</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="反向代理　　服务器代理网络上的客户机请求，将请求转达给内部真实服务器，然后再返回给Internet客户端，代理服务器上面没有任何网页资料。反向代理和正向代理没有冲突，可以在防火墙设备中同时使用这两种结合，正向代理可以进行过滤，保护内部网络安全。软件七层负载均衡大多是基于HTTP反向代理，Nginx反向代理能够支持虚拟主机，可以按照轮询，IP哈希，URL哈希，权重方式对后端服务器做负载均衡，同时还支">
<meta property="og:type" content="article">
<meta property="og:title" content="Nginx系列二之反向代理">
<meta property="og:url" content="http://yoursite.com/2015/12/17/nginx/2.Nginx系列之反向代理/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="反向代理　　服务器代理网络上的客户机请求，将请求转达给内部真实服务器，然后再返回给Internet客户端，代理服务器上面没有任何网页资料。反向代理和正向代理没有冲突，可以在防火墙设备中同时使用这两种结合，正向代理可以进行过滤，保护内部网络安全。软件七层负载均衡大多是基于HTTP反向代理，Nginx反向代理能够支持虚拟主机，可以按照轮询，IP哈希，URL哈希，权重方式对后端服务器做负载均衡，同时还支">
<meta property="og:updated_time" content="2016-01-29T17:47:36.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Nginx系列二之反向代理">
<meta name="twitter:description" content="反向代理　　服务器代理网络上的客户机请求，将请求转达给内部真实服务器，然后再返回给Internet客户端，代理服务器上面没有任何网页资料。反向代理和正向代理没有冲突，可以在防火墙设备中同时使用这两种结合，正向代理可以进行过滤，保护内部网络安全。软件七层负载均衡大多是基于HTTP反向代理，Nginx反向代理能够支持虚拟主机，可以按照轮询，IP哈希，URL哈希，权重方式对后端服务器做负载均衡，同时还支">
  
    <link rel="alternative" href="/atom.xml" title="Hexo" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  <link rel="stylesheet" href="/css/style.css" type="text/css">
  

</head>
<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">Hexo</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" results="0" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://yoursite.com"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-nginx/2.Nginx系列之反向代理" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2015/12/17/nginx/2.Nginx系列之反向代理/" class="article-date">
  <time datetime="2015-12-16T18:00:00.000Z" itemprop="datePublished">2015-12-17</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/nginx/">nginx</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      Nginx系列二之反向代理
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="u53CD_u5411_u4EE3_u7406"><a href="#u53CD_u5411_u4EE3_u7406" class="headerlink" title="反向代理"></a>反向代理</h2><p>　　服务器代理网络上的客户机请求，将请求转达给内部真实服务器，然后再返回给Internet客户端，代理服务器上面没有任何网页资料。反向代理和正向代理没有冲突，可以在防火墙设备中同时使用这两种结合，正向代理可以进行过滤，保护内部网络安全。软件七层负载均衡大多是基于HTTP反向代理，Nginx反向代理能够支持虚拟主机，可以按照轮询，IP哈希，URL哈希，权重方式对后端服务器做负载均衡，同时还支持热备（failover）的功能，还支持后端服务器健康检查。<br>　　反向代理的典型用途是将防火墙后面的服务器提供给Internet用户访问。反向代理还可以为后端的多台服务器提供负载平衡，或为后端较慢的服务器提供缓冲服务。</p>
<p>资料下载：<a href="/code/第6章 Nginx HTTP负载均衡和反向代理的配置与优化.pdf">Nginx HTTP负载均衡和反向代理的配置与优化.pdf</a></p>
<h2 id="u4EE3_u7406_u79CD_u7C7B"><a href="#u4EE3_u7406_u79CD_u7C7B" class="headerlink" title="代理种类"></a>代理种类</h2><p>1.硬件四/七负载均衡设备<br>2.软件四层负载设备，代表作品为LVS(Linux Virtual Server)<br>3.软件七层负载均衡，代表产品有Nginx，L7SW，HAProxy</p>
<h2 id="u5206_u914D_u65B9_u5F0F"><a href="#u5206_u914D_u65B9_u5F0F" class="headerlink" title="分配方式"></a>分配方式</h2><p>　　1. 轮询（默认）：每个请求按时间顺序逐一分配到后端服务器。如果后端服务器down掉，能自动剔除，但如果一台服务器发生故障，那么所有的访问该服务器的请求将不会有所回应<br>upstream test{<br>    server 192.168.0.1:3000;<br>    server 192.168.0.1:3001;<br>}</p>
<p>　　2. weight：指定轮询几率，weight和访问比率成正比，用于后端服务器性能不均的情况<br>upstream test{<br>    server 192.168.0.1 weight=2;<br>    server 192.168.0.2 weight=3;<br>}</p>
<p>　　3. ip_hash：每个请求按访问ip的hash结果分配，这样每个访客固定访问一个后端服务器，可以解决session的问题？？？？（好像不行）<br>upstream test{<br>    ip_hash;<br>    server 192.168.0.1;<br>    server 192.168.0.2;<br>}</p>
<p>　　4. fair（第三方）：需要安装Upstream Fair Balancer Module，按后端服务器的响应时间来分配请求，响应时间短的优先分配。<br>upstream resinserver{<br>    server server1;<br>    server server2;<br>    fair;<br>}<br>　　5. url_hash（第三方）按访问url的hash结果来分配请求，使每个url定向到同一个后端服务器，后端服务器为缓存时比较有效。<br>例：在upstream中加入hash语句，server语句中不能写入weight等其他的参数，hash_method是使用的hash算法</p>
<p>upstream resinserver{<br>    server squid1:3128;<br>    server squid2:3128;<br>    hash $request_uri;<br>    hash_method crc32;<br>}</p>
<h2 id="u53C2_u6570_u914D_u7F6E"><a href="#u53C2_u6570_u914D_u7F6E" class="headerlink" title="参数配置"></a>参数配置</h2><p>　　我们可以在upstream模块中，为每个服务设置不同的参数，如下所示：<br>upstream resinserver{ #定义负载均衡设备的Ip及设备状态<br>    ip_hash;<br>    server 127.0.0.1:8000 down;<br>    server 127.0.0.1:8080 weight=2;<br>    server 127.0.0.1:6801;<br>    server 127.0.0.1:6802 backup;<br>}<br>　　每个设备的状态设置为:<br>　　1. down  表示当前的server暂时不参与负载<br>　　2. weight  默认为1。weight越大，负载的权重就越大。<br>　　3. max_fails  允许请求失败的次数默认为1.当超过最大次数时，返回proxy_next_upstream 模块定义的错误<br>　　4. fail_timeout  max_fails次失败后，暂停的时间。<br>　　5. backup  其它所有的非backup机器down或者忙的时候，请求backup机器。所以这台机器压力会最轻。</p>
<p>nginx支持同时设置多组的负载均衡，用来给不用的server来使用。<br>client_body_in_file_only 设置为On 可以讲client post过来的数据记录到文件中用来做debug<br>client_body_temp_path 设置记录文件的目录可以设置最多3层目录<br>location 对URL进行匹配，可以进行重定向或者进行新的代理负载均衡</p>
<h2 id="Nginx_u914D_u7F6E"><a href="#Nginx_u914D_u7F6E" class="headerlink" title="Nginx配置"></a>Nginx配置</h2><p>　　nginx的反向代理主要由upstream模块负责，实例配置如下<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#使用的用户和组</span></span><br><span class="line"><span class="comment">#user nobody;</span></span><br><span class="line"><span class="comment">#指定工作衍生进程数，一般等于工作进程的总核数或者总核数的两倍</span></span><br><span class="line">worker_processes <span class="number">1</span>;</span><br><span class="line"><span class="comment">#pid logs/nginx.pid;</span></span><br><span class="line"><span class="comment">#指定错误日志存放的路径和级别（debug info notice warn error crit）</span></span><br><span class="line">error_<span class="built_in">log</span> /data/logs/nginx_error.log crit</span><br><span class="line">events &#123;</span><br><span class="line">　　<span class="comment">#使用的网络I/O模型，Linux系统推荐采用epoll模型</span></span><br><span class="line">　　use epoll;</span><br><span class="line">　　<span class="comment">#允许的连接数</span></span><br><span class="line">    worker_connections <span class="number">1024</span>;</span><br><span class="line">&#125;</span><br><span class="line">http &#123;</span><br><span class="line">    include mime.types;</span><br><span class="line">    default_<span class="built_in">type</span> application/octet-stream;</span><br><span class="line">    sendfile on;</span><br><span class="line">    keepalive_timeout <span class="number">65</span>;</span><br><span class="line">    <span class="comment">#gzip on;</span></span><br><span class="line">	<span class="comment">#客户端能够上传到文件大小</span></span><br><span class="line">    client_max_body_size <span class="number">8</span>m;</span><br><span class="line">    upstream cluster &#123;</span><br><span class="line">        <span class="comment">#server 192.98.12.60:1985 weight=3 max_fails=2 fail_timeout=30s;</span></span><br><span class="line">        server <span class="number">192.98</span>.<span class="number">12.42</span>:<span class="number">8086</span> weight=<span class="number">3</span> max_fails=<span class="number">2</span> fail_timeout=<span class="number">30</span>s;</span><br><span class="line">    &#125;</span><br><span class="line">    server &#123;</span><br><span class="line">        listen <span class="number">8090</span>;</span><br><span class="line">        server_name localhost;</span><br><span class="line">        <span class="comment">#charset koi8-r;</span></span><br><span class="line">        <span class="comment">#access_log logs/host.access.log main;</span></span><br><span class="line"></span><br><span class="line">        location / &#123;</span><br><span class="line">            root html;</span><br><span class="line">            index index.html index.htm;</span><br><span class="line">        &#125;</span><br><span class="line">        location /tileservice &#123; //<span class="comment">#url:"http://localhost:8090/tileservice?type=&#123;type&#125;&amp;x=&#123;x&#125;&amp;y=&#123;y&#125;&amp;l=&#123;l&#125;"</span></span><br><span class="line">            proxy_pass http://cluster/MongoTileService/tileService;</span><br><span class="line">            proxy_<span class="built_in">set</span>_header Host <span class="variable">$host</span>;</span><br><span class="line">            proxy_<span class="built_in">set</span>_header X-Forwarded-For <span class="variable">$proxy_add_x_forwarded_for</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        location ~ .*\.(apk|json)$ &#123; //<span class="comment">#http://192.98.12.67:8090/version.json</span></span><br><span class="line">            root android;</span><br><span class="line">            <span class="comment">#expires 30d;</span></span><br><span class="line">            index version.json; </span><br><span class="line">        &#125;</span><br><span class="line">        location /baidu &#123; </span><br><span class="line">            proxy_pass https://www.google.com.hk;</span><br><span class="line">            proxy_<span class="built_in">set</span>_header Host <span class="variable">$host</span>;</span><br><span class="line">            proxy_<span class="built_in">set</span>_header X-Forwarded-For <span class="variable">$proxy_add_x_forwarded_for</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<h2 id="u52A8_u9759_u5206_u79BB"><a href="#u52A8_u9759_u5206_u79BB" class="headerlink" title="动静分离"></a>动静分离</h2><p>　　有些时候，我们希望将共用的静态资源（比如：jquery、css），直接放在nginx下。背后的web app server，只处理动态资源(比如：.aspx/.do/.jsp)，可以改进一下：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">server &#123;</span><br><span class="line">	listen       <span class="number">80</span>;</span><br><span class="line">	server_name  www.aaa.com;</span><br><span class="line">	root R:/www/aaa.com;</span><br><span class="line">	location / &#123;</span><br><span class="line">		proxy_pass http://<span class="number">192.168</span>.<span class="number">1.201</span>:<span class="number">8080</span> ;</span><br><span class="line">		proxy_<span class="built_in">set</span>_header Host <span class="variable">$host</span>:<span class="number">8080</span>;</span><br><span class="line">		proxy_<span class="built_in">set</span>_header X-Real-IP <span class="variable">$remote_addr</span>;</span><br><span class="line">		proxy_<span class="built_in">set</span>_header X-Forwarded-For <span class="variable">$proxy_add_x_forwarded_for</span>;</span><br><span class="line">		proxy_<span class="built_in">set</span>_header Via <span class="string">"nginx"</span>;</span><br><span class="line">	&#125;</span><br><span class="line">	location ~ .*\.(js|css)?$ &#123;</span><br><span class="line">		expires <span class="number">1</span>h;</span><br><span class="line">	&#125;</span><br><span class="line">	access_<span class="built_in">log</span> off;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>　　这样，访问<a href="http://www.aaa.com/content/site.css" target="_blank" rel="external">http://www.aaa.com/content/site.css</a> 时实际上读取的是R:/www/aaa.com/content/site.css 这个文件</p>
<h2 id="u865A_u62DF_u4E3B_u673A"><a href="#u865A_u62DF_u4E3B_u673A" class="headerlink" title="虚拟主机"></a>虚拟主机</h2><p>　　这里配置了二个虚拟主机，分别绑定到域名www.aaa.com及www.bbb.com，详见资源<a href="/code/第3章 Nginx的基本配置与优化.pdf">Nginx的基本配置与优化.pdf</a><br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">server &#123;</span><br><span class="line">	listen       <span class="number">80</span>;</span><br><span class="line">	server_name  www.aaa.com;</span><br><span class="line">	access_<span class="built_in">log</span> logs/aaa.access.log combined;</span><br><span class="line">	location / &#123;</span><br><span class="line">		root   r:/www/aaa.com;</span><br><span class="line">		index  index.html index.htm;</span><br><span class="line">	&#125;       </span><br><span class="line">&#125;</span><br><span class="line">server &#123;</span><br><span class="line">	listen       <span class="number">80</span>;</span><br><span class="line">	server_name  www.bbb.com;</span><br><span class="line">	access_<span class="built_in">log</span> logs/bbb.access.log combined;</span><br><span class="line">	location / &#123;</span><br><span class="line">		root   r:/www/bbb.com;</span><br><span class="line">		index  index.html index.htm;</span><br><span class="line">	&#125;       </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>　　我们再看另一个配置，该配置主要实现的功能如下：</p>
<ol>
<li>用户访问<a href="http://www.zyan.cc，将其负载均衡到192.168.1.2:80、192.168.1.3:80、192.168.1.4:80、192.168.1.5:80四台服务器。" target="_blank" rel="external">http://www.zyan.cc，将其负载均衡到192.168.1.2:80、192.168.1.3:80、192.168.1.4:80、192.168.1.5:80四台服务器。</a></li>
<li>用户访问<a href="http://blog.zyan.cc，将其负载均衡到192.168.1.7服务器的8080、8081、8082端口。" target="_blank" rel="external">http://blog.zyan.cc，将其负载均衡到192.168.1.7服务器的8080、8081、8082端口。</a></li>
</ol>
<p>nginx.conf配置文件如下：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br></pre></td><td class="code"><pre><span class="line">user  www www;</span><br><span class="line"></span><br><span class="line">worker_processes <span class="number">10</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">#error_log  logs/error.log;</span></span><br><span class="line"><span class="comment">#error_log  logs/error.log  notice;</span></span><br><span class="line"><span class="comment">#error_log  logs/error.log  info;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#pid        logs/nginx.pid;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#最大文件描述符</span></span><br><span class="line">worker_rlimit_nofile <span class="number">51200</span>;</span><br><span class="line"></span><br><span class="line">events &#123;</span><br><span class="line">      use epoll;</span><br><span class="line"></span><br><span class="line">      worker_connections <span class="number">51200</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">http &#123;</span><br><span class="line">      include       conf/mime.types;</span><br><span class="line">      default_<span class="built_in">type</span>  application/octet-stream;</span><br><span class="line"></span><br><span class="line">      keepalive_timeout <span class="number">120</span>;</span><br><span class="line"></span><br><span class="line">      tcp_nodelay on;</span><br><span class="line"></span><br><span class="line">      upstream  www.zyan.cc  &#123;</span><br><span class="line">              server   <span class="number">192.168</span>.<span class="number">1.2</span>:<span class="number">80</span>;</span><br><span class="line">              server   <span class="number">192.168</span>.<span class="number">1.3</span>:<span class="number">80</span>;</span><br><span class="line">              server   <span class="number">192.168</span>.<span class="number">1.4</span>:<span class="number">80</span>;</span><br><span class="line">              server   <span class="number">192.168</span>.<span class="number">1.5</span>:<span class="number">80</span>;</span><br><span class="line">      &#125;</span><br><span class="line"></span><br><span class="line">      upstream  blog.zyan.cc  &#123;</span><br><span class="line">              server   <span class="number">192.168</span>.<span class="number">1.7</span>:<span class="number">8080</span>;</span><br><span class="line">              server   <span class="number">192.168</span>.<span class="number">1.7</span>:<span class="number">8081</span>;</span><br><span class="line">              server   <span class="number">192.168</span>.<span class="number">1.7</span>:<span class="number">8082</span>;</span><br><span class="line">      &#125;</span><br><span class="line"></span><br><span class="line">      server&#123;</span><br><span class="line">              listen  <span class="number">80</span>;</span><br><span class="line">              server_name  www.zyan.cc;</span><br><span class="line"></span><br><span class="line">              location / &#123;</span><br><span class="line">                       proxy_pass        http://www.zyan.cc;</span><br><span class="line">                       proxy_<span class="built_in">set</span>_header   Host             <span class="variable">$host</span>;</span><br><span class="line">                       proxy_<span class="built_in">set</span>_header   X-Real-IP        <span class="variable">$remote_addr</span>;</span><br><span class="line">                       proxy_<span class="built_in">set</span>_header   X-Forwarded-For  <span class="variable">$proxy_add_x_forwarded_for</span>;</span><br><span class="line">              &#125;</span><br><span class="line"></span><br><span class="line">              <span class="built_in">log</span>_format  www_s135_com  <span class="string">'$remote_addr - $remote_user [$time_local] $request '</span></span><br><span class="line">                                <span class="string">'"$status" $body_bytes_sent "$http_referer" '</span></span><br><span class="line">                                <span class="string">'"$http_user_agent" "$http_x_forwarded_for"'</span>;</span><br><span class="line">              access_<span class="built_in">log</span>  /data1/logs/www.log  www_s135_com;</span><br><span class="line">      &#125;</span><br><span class="line"></span><br><span class="line">      server&#123;</span><br><span class="line">              listen  <span class="number">80</span>;</span><br><span class="line">              server_name  blog.zyan.cc;</span><br><span class="line"></span><br><span class="line">              location / &#123;</span><br><span class="line">                       proxy_pass        http://blog.zyan.cc;</span><br><span class="line">                       proxy_<span class="built_in">set</span>_header   Host             <span class="variable">$host</span>;</span><br><span class="line">                       proxy_<span class="built_in">set</span>_header   X-Real-IP        <span class="variable">$remote_addr</span>;</span><br><span class="line">                       proxy_<span class="built_in">set</span>_header   X-Forwarded-For  <span class="variable">$proxy_add_x_forwarded_for</span>;</span><br><span class="line">              &#125;</span><br><span class="line"></span><br><span class="line">              <span class="built_in">log</span>_format  blog_s135_com  <span class="string">'$remote_addr - $remote_user [$time_local] $request '</span></span><br><span class="line">                                <span class="string">'"$status" $body_bytes_sent "$http_referer" '</span></span><br><span class="line">                                <span class="string">'"$http_user_agent" "$http_x_forwarded_for"'</span>;</span><br><span class="line">              access_<span class="built_in">log</span>  /data1/logs/blog.log  blog_s135_com;</span><br><span class="line">      &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2015/12/17/nginx/2.Nginx系列之反向代理/" data-id="cijzzpv8a006r1cfslz0qv2yn" class="article-share-link">Share</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/nginx/">nginx</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2015/12/17/nginx/3.HAproxy配置/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          HAproxy配置
        
      </div>
    </a>
  
  
    <a href="/2015/12/17/nginx/1.Nginx系列之简介与配置/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">Nginx系列一之简介与配置</div>
    </a>
  
</nav>

  
</article>

</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Categories</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/cache/">cache</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/database/">database</a><span class="category-list-count">13</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/docker/">docker</a><span class="category-list-count">6</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/gis/">gis</a><span class="category-list-count">4</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/git/">git</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/go/">go</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/gradle/">gradle</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/groovy/">groovy</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/hadoop/">hadoop</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/java/">java</a><span class="category-list-count">18</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/linux/">linux</a><span class="category-list-count">4</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/log/">log</a><span class="category-list-count">11</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/mongodb/">mongodb</a><span class="category-list-count">14</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/mq/">mq</a><span class="category-list-count">6</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/mybatis/">mybatis</a><span class="category-list-count">9</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/netty/">netty</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/nginx/">nginx</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/nio/">nio</a><span class="category-list-count">19</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/nodejs/">nodejs</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/redis/">redis</a><span class="category-list-count">6</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/rpc/">rpc</a><span class="category-list-count">14</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/spring/">spring</a><span class="category-list-count">5</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/tomcat/">tomcat</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/zookeeper/">zookeeper</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/杂项/">杂项</a><span class="category-list-count">2</span></li></ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/aop/">aop</a><span class="tag-list-count">8</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/aspectj/">aspectj</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/cache/">cache</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/classloader/">classloader</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/common-loggings/">common-loggings</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/commonjs/">commonjs</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/database/">database</a><span class="tag-list-count">10</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/docker/">docker</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/dubbo/">dubbo</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/fastdfs/">fastdfs</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/gclib/">gclib</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/geohash/">geohash</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/gis/">gis</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/git/">git</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/go/">go</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/gradle/">gradle</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/groovy/">groovy</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/hadoop/">hadoop</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/hessisan/">hessisan</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/java/">java</a><span class="tag-list-count">48</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/javassist/">javassist</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/kafka/">kafka</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/linux/">linux</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/log/">log</a><span class="tag-list-count">11</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/log4j/">log4j</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/logback/">logback</a><span class="tag-list-count">5</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/map/">map</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/memecached/">memecached</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mina/">mina</a><span class="tag-list-count">5</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mongodb/">mongodb</a><span class="tag-list-count">14</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mq/">mq</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mqtt/">mqtt</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mybatis/">mybatis</a><span class="tag-list-count">9</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/netty/">netty</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/nginx/">nginx</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/nio/">nio</a><span class="tag-list-count">5</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/nodejs/">nodejs</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/postgresql/">postgresql</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/protobuf/">protobuf</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/proxy/">proxy</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/push/">push</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/rabbitmq/">rabbitmq</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/redis/">redis</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/rpc/">rpc</a><span class="tag-list-count">14</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/sitemesh/">sitemesh</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/sld/">sld</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/slf4j/">slf4j</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/socket/">socket</a><span class="tag-list-count">7</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/spatialite-for-android/">spatialite for android</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/spi/">spi</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/spring/">spring</a><span class="tag-list-count">13</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/tomcat/">tomcat</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/transaction/">transaction</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/web/">web</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/xSocket/">xSocket</a><span class="tag-list-count">7</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/zbus/">zbus</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/zookeeper/">zookeeper</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/数据结构/">数据结构</a><span class="tag-list-count">2</span></li></ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/tags/aop/" style="font-size: 15.38px;">aop</a> <a href="/tags/aspectj/" style="font-size: 11.54px;">aspectj</a> <a href="/tags/cache/" style="font-size: 11.54px;">cache</a> <a href="/tags/classloader/" style="font-size: 10px;">classloader</a> <a href="/tags/common-loggings/" style="font-size: 10px;">common-loggings</a> <a href="/tags/commonjs/" style="font-size: 12.31px;">commonjs</a> <a href="/tags/database/" style="font-size: 16.92px;">database</a> <a href="/tags/docker/" style="font-size: 13.85px;">docker</a> <a href="/tags/dubbo/" style="font-size: 10px;">dubbo</a> <a href="/tags/fastdfs/" style="font-size: 10px;">fastdfs</a> <a href="/tags/gclib/" style="font-size: 10.77px;">gclib</a> <a href="/tags/geohash/" style="font-size: 10px;">geohash</a> <a href="/tags/gis/" style="font-size: 10px;">gis</a> <a href="/tags/git/" style="font-size: 10.77px;">git</a> <a href="/tags/go/" style="font-size: 10px;">go</a> <a href="/tags/gradle/" style="font-size: 10px;">gradle</a> <a href="/tags/groovy/" style="font-size: 10px;">groovy</a> <a href="/tags/hadoop/" style="font-size: 10px;">hadoop</a> <a href="/tags/hessisan/" style="font-size: 11.54px;">hessisan</a> <a href="/tags/java/" style="font-size: 20px;">java</a> <a href="/tags/javassist/" style="font-size: 10px;">javassist</a> <a href="/tags/kafka/" style="font-size: 11.54px;">kafka</a> <a href="/tags/linux/" style="font-size: 12.31px;">linux</a> <a href="/tags/log/" style="font-size: 17.69px;">log</a> <a href="/tags/log4j/" style="font-size: 12.31px;">log4j</a> <a href="/tags/logback/" style="font-size: 13.08px;">logback</a> <a href="/tags/map/" style="font-size: 10px;">map</a> <a href="/tags/memecached/" style="font-size: 10.77px;">memecached</a> <a href="/tags/mina/" style="font-size: 13.08px;">mina</a> <a href="/tags/mongodb/" style="font-size: 19.23px;">mongodb</a> <a href="/tags/mq/" style="font-size: 13.85px;">mq</a> <a href="/tags/mqtt/" style="font-size: 10.77px;">mqtt</a> <a href="/tags/mybatis/" style="font-size: 16.15px;">mybatis</a> <a href="/tags/netty/" style="font-size: 10px;">netty</a> <a href="/tags/nginx/" style="font-size: 11.54px;">nginx</a> <a href="/tags/nio/" style="font-size: 13.08px;">nio</a> <a href="/tags/nodejs/" style="font-size: 10px;">nodejs</a> <a href="/tags/postgresql/" style="font-size: 10.77px;">postgresql</a> <a href="/tags/protobuf/" style="font-size: 10px;">protobuf</a> <a href="/tags/proxy/" style="font-size: 10px;">proxy</a> <a href="/tags/push/" style="font-size: 10px;">push</a> <a href="/tags/rabbitmq/" style="font-size: 11.54px;">rabbitmq</a> <a href="/tags/redis/" style="font-size: 13.85px;">redis</a> <a href="/tags/rpc/" style="font-size: 19.23px;">rpc</a> <a href="/tags/sitemesh/" style="font-size: 10px;">sitemesh</a> <a href="/tags/sld/" style="font-size: 10px;">sld</a> <a href="/tags/slf4j/" style="font-size: 10px;">slf4j</a> <a href="/tags/socket/" style="font-size: 14.62px;">socket</a> <a href="/tags/spatialite-for-android/" style="font-size: 10px;">spatialite for android</a> <a href="/tags/spi/" style="font-size: 10px;">spi</a> <a href="/tags/spring/" style="font-size: 18.46px;">spring</a> <a href="/tags/tomcat/" style="font-size: 10.77px;">tomcat</a> <a href="/tags/transaction/" style="font-size: 10px;">transaction</a> <a href="/tags/web/" style="font-size: 10px;">web</a> <a href="/tags/xSocket/" style="font-size: 14.62px;">xSocket</a> <a href="/tags/zbus/" style="font-size: 10px;">zbus</a> <a href="/tags/zookeeper/" style="font-size: 10.77px;">zookeeper</a> <a href="/tags/数据结构/" style="font-size: 10.77px;">数据结构</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/01/">January 2016</a><span class="archive-list-count">67</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/12/">December 2015</a><span class="archive-list-count">81</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/11/">November 2015</a><span class="archive-list-count">2</span></li></ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recents</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2016/01/30/资料/">(no title)</a>
          </li>
        
          <li>
            <a href="/2016/01/30/java/13.Classloader系列一/">ClassLoader系列一</a>
          </li>
        
          <li>
            <a href="/2016/01/29/hadoop/1.hadoop系列之源码编译/">hadoop系列一之源码编译</a>
          </li>
        
          <li>
            <a href="/2016/01/29/go/1.GO系列之入门/">Go系列一之入门</a>
          </li>
        
          <li>
            <a href="/2016/01/28/tomcat/2.tomcat性能优化/">tomcat性能优化</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2016 John Doe<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    


<script src="http://libs.baidu.com/jquery/2.0.3/jquery.min.js"></script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css" type="text/css">
  <script src="/fancybox/jquery.fancybox.pack.js" type="text/javascript"></script>


<script src="/js/script.js" type="text/javascript"></script>

  </div>
</body>
</html>